import router from '@/vue/router'
import { delActiveMenu } from './store'

//跳转路由
export const toRoute = (to, option = {}) => {
  const { params, from } = option
  if (!to || to === from) return null
  const route = { name: to }
  params && (route.params = params)
  router.push(route)
}

//根据route,关闭菜单, 并判断是否要跳转路由
export const closeTag = route => {
  const name = delActiveMenu(route)
  const from = router.currentRoute.name
  route === from &&
    name &&
    toRoute(name, {
      from,
      params: {
        close: true
      }
    })
}
